﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// job_list 的摘要说明
    /// </summary>
    public class map_list : IHttpHandler, IRequiresSessionState
    {
        protected int totalCount = 0;
        protected int page = 1;
        protected int pageSize = 0;
        public void ProcessRequest(HttpContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取供应信息
            BLL.quanzi bll = new BLL.quanzi();
            DataSet ds = bll.GetList(0, "status=1 and zuobiao!=''", "id desc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"map_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    string[] sArray = dr["zuobiao"].ToString().Split(',');
                    strTxt.Append(",\"lng\":" + sArray[0]);
                    strTxt.Append(",\"lat\":" + sArray[1]);
                    string _area = string.Empty;
                    if (Convert.ToInt32(dr["province_id"]) > 0)
                    {
                        _area += new BLL.province().GetTitle(Convert.ToInt32(dr["province_id"]));
                    }
                    if (Convert.ToInt32(dr["city_id"]) > 0)
                    {
                        _area += new BLL.city().GetTitle(Convert.ToInt32(dr["city_id"]));
                    }
                    if (Convert.ToInt32(dr["district_id"]) > 0)
                    {
                        _area += new BLL.district().GetTitle(Convert.ToInt32(dr["district_id"]));
                    }
                    strTxt.Append(",\"area\":\"" + _area + "\"");
                    strTxt.Append(",\"class_id\":" + dr["category_id"]);
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            strTxt.Append("\"result\":" + ds.Tables[0].Rows.Count.ToString() + "");
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}